/**
 *
 */
package com.zhuoyue.elmt.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.eit.eitsite.common.utils.IdGen;
import com.eit.eitsite.modules.sys.dao.MenuDao;
import com.eit.eitsite.modules.sys.dao.RoleDao;
import com.eit.eitsite.modules.sys.entity.Area;
import com.eit.eitsite.modules.sys.entity.Office;
import com.eit.eitsite.modules.sys.entity.Role;
import com.eit.eitsite.modules.sys.entity.User;
import com.eit.eitsite.modules.sys.service.OfficeService;
import com.eit.eitsite.modules.sys.service.SystemService;
import com.eit.eitsite.modules.sys.utils.DictUtils;
import com.eit.eitsite.modules.sys.utils.UserUtils;
import com.fasterxml.jackson.databind.BeanProperty;
import com.google.common.collect.Lists;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.eit.eitsite.common.config.Global;
import com.eit.eitsite.common.persistence.Page;
import com.eit.eitsite.common.web.BaseController;
import com.eit.eitsite.common.utils.StringUtils;
import com.zhuoyue.elmt.entity.GgZgdw;
import com.zhuoyue.elmt.service.GgZgdwService;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 资格单位信息Controller
 *
 * @author chenhao
 * @version 2016-09-08
 */
@Controller
@RequestMapping(value = "${adminPath}/elmt/ggZgdw")
public class GgZgdwController extends BaseController {

    @Autowired
    private GgZgdwService ggZgdwService;

    @ModelAttribute
    public GgZgdw get(@RequestParam(required = false) String id) {
        GgZgdw entity = null;
        if (StringUtils.isNotBlank(id)) {
            entity = ggZgdwService.get(id);
        }
        if (entity == null) {
            entity = new GgZgdw();
        }
        return entity;
    }

    @RequiresPermissions("elmt:ggZgdw:view")
    @RequestMapping(value = {"list", ""})
    public String list(GgZgdw ggZgdw, HttpServletRequest request, HttpServletResponse response, Model model) {
        Page<GgZgdw> page = ggZgdwService.findPage(new Page<GgZgdw>(request, response), ggZgdw);
        model.addAttribute("page", page);
        return "zhuoyue/elmt/ggZgdwList";
    }

    @RequiresPermissions("elmt:ggZgdw:view")
    @RequestMapping(value = "form")
    public String form(GgZgdw ggZgdw, Model model) {
        model.addAttribute("ggZgdw", ggZgdw);
        return "zhuoyue/elmt/ggZgdwForm";
    }

    @RequiresPermissions("elmt:ggZgdw:edit")
    @RequestMapping(value = "save")
    public String save(GgZgdw ggZgdw, Model model, RedirectAttributes redirectAttributes) {
        if (!beanValidator(model, ggZgdw)) {
            return form(ggZgdw, model);
        }
        ggZgdwService.save(ggZgdw);
        addMessage(redirectAttributes, "维保单位信息成功");
        return "redirect:" + Global.getAdminPath() + "/elmt/ggZgdw/?repage";
    }

    @RequiresPermissions("elmt:ggZgdw:edit")
    @RequestMapping(value = "delete")
    public String delete(GgZgdw ggZgdw, RedirectAttributes redirectAttributes) {
        ggZgdwService.delete(ggZgdw);
        addMessage(redirectAttributes, "删除维保单位信息成功");
        return "redirect:" + Global.getAdminPath() + "/elmt/ggZgdw/?repage";
    }

    @RequiresPermissions("elmt:ggZgdw:edit")
    @RequestMapping(value = {"initaccess"})
    public String initaccess(GgZgdw ggZgdw, HttpServletRequest request, HttpServletResponse response, Model model, RedirectAttributes redirectAttributes) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        ggZgdwService.initaccess(ggZgdw);
        addMessage(redirectAttributes, "单位接入初始化成功");
        return "redirect:" + Global.getAdminPath() + "/elmt/ggZgdw/?repage";
    }

    @RequiresPermissions("elmt:ggZgdw:edit")
    @RequestMapping(value = {"removeaccess"})
    public String removeaccess(GgZgdw ggZgdw, HttpServletRequest request, HttpServletResponse response, Model model, RedirectAttributes redirectAttributes) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        ggZgdwService.removeaccess(ggZgdw);
        addMessage(redirectAttributes, "去掉单位接入成功");
        return "redirect:" + Global.getAdminPath() + "/elmt/ggZgdw/?repage";
    }

}